import { SEntityId } from "../../../../Message/Public/SEntityId";
import { Cache } from "../../cache/Cache";
import { DateUtil } from "../../../common/tools/DateUtil";
import { ClockManager } from "../../manager/ClockManager";
import { PetIslandStateData } from "./vo/PetIslandStateData";
import { ResFileConst } from "../../resource/ResFileConst";
import { SRobIslandPlayer } from "../../../../Message/Game/SRobIslandPlayer";
import { Language } from "../../../../extend/language/Language";
import { SIslandPos } from "../../../../Message/Game/SIslandPos";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { ColorConfig } from "../../resource/ColorConfig";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { EGuildPos } from "../../../../Message/Game/EGuildPos";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
type int = number;
//class PetIslandUtil
    
    export  class PetIslandUtil
    {
        

        public static isInGuild(arg1: SEntityId): Boolean
        {
            var loc1=Cache.instance.role.entityInfo;
            return Cache.instance.guild.myGuildInfo && Cache.instance.guild.myGuildInfo.guildId == arg1.id && loc1.entityId.typeEx == arg1.typeEx && loc1.entityId.typeEx2 == arg1.typeEx2;
        }

        public static get canApply(): Boolean
        {
            if (Cache.instance.guild.myGuildInfo) 
            {
                return DateUtil.getSecondsDis(Cache.instance.guild.myGuildInfo.lastEnterDt, ClockManager.instance.nowDate) >= 24 * 60 * 60;
            }
            return false;
        }

        public static getState(arg1: PetIslandStateData): string
        {
            if (arg1.isFighting) 
            {
                return ResFileConst.PetIslandFighttingBtn;
            }
            if (arg1.protectSeconds > 0) 
            {
                return ResFileConst.PetIslandDefendBtn;
            }
            return "";
        }

        public static getPosition(arg1: SRobIslandPlayer, arg2: Boolean=false): string
        {
            if (arg1.pos.isLand == 0) 
            {
                return Language.getString(28149);
            }
            return PetIslandUtil.getPosName(arg1.pos);
        }

        public static isReinforce(arg1: Array<any>): Boolean
        {
            var loc2=null;
            var loc1=Cache.instance.role.entityInfo.entityId.id;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                if (loc2.entityId.id != loc1) 
                {
                    continue;
                }
                return true;
            }
            return false;
        }

        public static isInPlace(arg1: SIslandPos): Boolean
        {
            var loc1=Cache.instance.petIsland.playerInfo;
            return loc1 && loc1.pos.isLand == arg1.isLand && loc1.pos.placeType == arg1.placeType && loc1.pos.x == arg1.x && loc1.pos.y == arg1.y;
        }

        public static getPosName(arg1: SIslandPos, arg2: Boolean=true, arg3: Boolean=true): string
        {
            var loc1=HTMLUtil.removeHtml(GameDefConfig.instance.getPetIslandName(arg1.isLand));
            var loc2=ColorConfig.instance.getItemColorString(arg1.isLand + 2);
            var loc3=ColorConfig.instance.getItemColorString(arg1.placeType + 2);
            var loc4=HTMLUtil.addColor(GameDefConfig.instance.getFigureToLetter(arg1.y + 1) + (arg1.x + 1), loc3);
            var loc5=HTMLUtil.addColor(loc1, loc2);
            if (arg2) 
            {
                if (arg3) 
                {
                    return Language.getStringByParam(28126, loc2, loc1 + " " + loc4);
                }
                return loc5 + " " + loc4;
            }
            return Language.getStringByParam(28126, loc2, " " + loc4);
        }

        public static get petComboDp(): DataProvider
        {
            var loc3=null;
            var loc1=new DataProvider();
            var loc2=Cache.instance.pet.petInfos;
            var loc4=0;
            while (loc4 < loc2.length) 
            {
                loc3 = loc2[loc4] as SPetInfo;
                if (loc3.reinLevel > 0 && !loc3.isBorrow) 
                {
                    loc1.addItem({"label": loc3.name, "value": loc3});
                }
                ++loc4;
            }
            return loc1;
        }

        public static setSelectPet(arg1: GComboBox, arg2: int): void
        {
            var loc1=null;
            var loc2=arg1.dataProvider.length;
            var loc3=0;
            while (loc3 < loc2) 
            {
                loc1 = arg1.dataProvider.getItemAt(loc3).value as SPetInfo;
                if (loc1.petId == arg2) 
                {
                    arg1.selectedIndex = loc3;
                    break;
                }
                ++loc3;
            }
            return;
        }

        public static getAdditionByPos(arg1: int): int
        {
            var loc1=0;
            var loc2=GameDefConfig.instance.getItem("EGuildPos", arg1);
            if (loc2) 
            {
                loc1 = int(loc2.text2);
            }
            return loc1;
        }

        public static getAdditionNum(arg1: int): string
        {
            var loc1=Cache.instance.petIsland.playerInfo;
            if (loc1 && loc1.guildPos > EGuildPos._EGuildPosMember) 
            {
                return HTMLUtil.addColor("  (+" + Math.ceil(arg1 * PetIslandUtil.getAdditionByPos(loc1.guildPos) / 100) + ")", GlobalStyle.color5);
            }
            return "";
        }

        public static sortMember(arg1: SRobIslandPlayer, arg2: SRobIslandPlayer): int
        {
            if (arg1.pos.isLand != arg2.pos.isLand) 
            {
                if (arg1.pos.isLand == 0 && !(arg2.pos.isLand == 0)) 
                {
                    return -1;
                }
                if (arg2.pos.isLand == 0 && !(arg1.pos.isLand == 0)) 
                {
                    return 1;
                }
                if (arg1.pos.isLand > arg2.pos.isLand) 
                {
                    return -1;
                }
                if (arg1.pos.isLand < arg2.pos.isLand) 
                {
                    return 1;
                }
            }
            else if (arg1.pos.y == arg2.pos.y) 
            {
                if (arg1.pos.x < arg2.pos.x) 
                {
                    return -1;
                }
                if (arg1.pos.x > arg2.pos.x) 
                {
                    return 1;
                }
            }
            return 0;
        }

        public static /* const */MAP_ID: int=900809;

        public static /* const */MAP_SIZE: int=160;

        public static /* const */mapSizeDic: Object={1: 3200, 2: 1920, 3: 1280};
    }
